﻿using System;
using System.Data;
using System.Collections.Generic;
using Maticsoft.Common;
using Travel.Model;
namespace Travel.BLL
{
	/// <summary>
	/// order
	/// </summary>
	public partial class orders
	{
		private readonly Travel.DAL.orders dal=new Travel.DAL.orders();
		public orders()
		{}
		#region  Method
		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(Guid id)
		{
			return dal.Exists(id);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(Travel.Model.orders model)
		{
			return dal.Add(model);
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Travel.Model.orders model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(Guid id)
		{
			
			return dal.Delete(id);
		}
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteList(string idlist )
		{
			return dal.DeleteList(idlist );
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Travel.Model.orders GetModel(Guid id)
		{
			
			return dal.GetModel(id);
		}

		/// <summary>
		/// 得到一个对象实体，从缓存中
		/// </summary>
		public Travel.Model.orders GetModelByCache(Guid id)
		{
			
			string CacheKey = "orderModel-" + id;
			object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
			if (objModel == null)
			{
				try
				{
					objModel = dal.GetModel(id);
					if (objModel != null)
					{
						int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
						Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
					}
				}
				catch{}
			}
			return (Travel.Model.orders)objModel;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			return dal.GetList(Top,strWhere,filedOrder);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<Travel.Model.orders> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<Travel.Model.orders> DataTableToList(DataTable dt)
		{
			List<Travel.Model.orders> modelList = new List<Travel.Model.orders>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				Travel.Model.orders model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = new Travel.Model.orders();
					if(dt.Rows[n]["id"]!=null && dt.Rows[n]["id"].ToString()!="")
					{
						model.id=new Guid(dt.Rows[n]["id"].ToString());
					}
					if(dt.Rows[n]["code"]!=null && dt.Rows[n]["code"].ToString()!="")
					{
					model.code=dt.Rows[n]["code"].ToString();
					}
					if(dt.Rows[n]["route_id"]!=null && dt.Rows[n]["route_id"].ToString()!="")
					{
						model.route_id=int.Parse(dt.Rows[n]["route_id"].ToString());
					}
					if(dt.Rows[n]["buyer_id"]!=null && dt.Rows[n]["buyer_id"].ToString()!="")
					{
						model.buyer_id=int.Parse(dt.Rows[n]["buyer_id"].ToString());
					}
					if(dt.Rows[n]["buyer_name"]!=null && dt.Rows[n]["buyer_name"].ToString()!="")
					{
					model.buyer_name=dt.Rows[n]["buyer_name"].ToString();
					}
					if(dt.Rows[n]["buyer_phone"]!=null && dt.Rows[n]["buyer_phone"].ToString()!="")
					{
					model.buyer_phone=dt.Rows[n]["buyer_phone"].ToString();
					}
					if(dt.Rows[n]["traveller_name"]!=null && dt.Rows[n]["traveller_name"].ToString()!="")
					{
					model.traveller_name=dt.Rows[n]["traveller_name"].ToString();
					}
					if(dt.Rows[n]["travller_phone"]!=null && dt.Rows[n]["travller_phone"].ToString()!="")
					{
					model.travller_phone=dt.Rows[n]["travller_phone"].ToString();
					}
					if(dt.Rows[n]["buy_time"]!=null && dt.Rows[n]["buy_time"].ToString()!="")
					{
						model.buy_time=DateTime.Parse(dt.Rows[n]["buy_time"].ToString());
					}
					if(dt.Rows[n]["travel_time"]!=null && dt.Rows[n]["travel_time"].ToString()!="")
					{
						model.travel_time=DateTime.Parse(dt.Rows[n]["travel_time"].ToString());
					}
					if(dt.Rows[n]["cost"]!=null && dt.Rows[n]["cost"].ToString()!="")
					{
						model.cost=decimal.Parse(dt.Rows[n]["cost"].ToString());
					}
					if(dt.Rows[n]["status"]!=null && dt.Rows[n]["status"].ToString()!="")
					{
						model.status=int.Parse(dt.Rows[n]["status"].ToString());
					}
					if(dt.Rows[n]["created_on"]!=null && dt.Rows[n]["created_on"].ToString()!="")
					{
						model.created_on=DateTime.Parse(dt.Rows[n]["created_on"].ToString());
					}
					if(dt.Rows[n]["changed_on"]!=null && dt.Rows[n]["changed_on"].ToString()!="")
					{
						model.changed_on=DateTime.Parse(dt.Rows[n]["changed_on"].ToString());
					}
					if(dt.Rows[n]["changed_by"]!=null && dt.Rows[n]["changed_by"].ToString()!="")
					{
					model.changed_by=dt.Rows[n]["changed_by"].ToString();
					}
					modelList.Add(model);
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			return dal.GetRecordCount(strWhere);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			return dal.GetListByPage( strWhere,  orderby,  startIndex,  endIndex);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		//public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		//{
			//return dal.GetList(PageSize,PageIndex,strWhere);
		//}

		#endregion  Method
	}
}

